	
var vue = new Vue({
  el: '#pageDiv',
  data :{
	  tableData : [],
	  loading: false,
	  currentPage : 1,
	  pagesize : 10,
	  totalSize : 10,
	  toListUrl:'/userMessage/to_menu_page',
	  queryUrl:COMMON_URL.URL+'userMessage/getMenu',
	  deleteUrl: COMMON_URL.URL+'userMessage/deleteMenu',
	  saveUrl: COMMON_URL.URL+'userMessage/saveMenu',
	  dialogAdd:false,
	  mesPermission:{
		  desc:'',
		  name :'',
		  url : '',
		  permission_int : ''
	  },
	  //form校验规则
	  rules:{
		  desc:[
            { required: true, message: '请输入菜单描述', trigger: 'blur' }
          ],
          name:[
	        { required: true, message: '请输入菜单名称', trigger: 'blur' }
	      ],
	      url:[
  	        { required: true, message: '请输入菜单URL', trigger: 'blur' }
  	      ]
	  }
  },
  methods:{
	  
	//打开新增看板配置弹窗
      openAddDialog(){
    	  this.dialogAdd =true;
      },
	  
	//关闭弹窗
      closeDialog(){
    	  this.dialogAdd = false;
      },
	  //查询数据
	  loadData(pageNum,pageSize){
		  $.ajax({
				url : this.queryUrl,
				dataType : 'json',
				type : 'get',
				data : {pageNum:pageNum,pageSize:pageSize},
				success : function(data){
					if(data.ok){
						var value = data.data.list;
						vue.tableData = value;
						vue.currentPage = data.data.currentPage;
						vue.totalSize = data.data.allCounts;
					}
				}
		  });
	  },
	  //分页
	  handleSizeChange(val){
		this.pagesize = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
	  //分页
	  handleCurrentChange(val){
		this.currentPage = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
      //删除看板配置
      deleteConfig(index,row,value){
		  const h = this.$createElement;
		  this.$msgbox({
			  title : "警告",
			  message : h('p', null, [
	            h('span', null, '你将要删除 '),
	            h('i', { style: 'color: teal' }, row.memo),
	            h('span', null, ' ?'),
	          ]),
	          showCancelButton: true,
	          confirmButtonText: '确定',
	          cancelButtonText: '取消',
	          beforeClose: (action, instance, done) => {
	              if (action === 'confirm') {
	                instance.confirmButtonLoading = true;
	                instance.confirmButtonText = '执行中...';
	        		$.ajax({
	        			type : 'get',
	        			dataType : 'json',
	        			data : {id : row.id},
	        			url : this.deleteUrl,
	        			success : function(data){
	        				if(data.ok){
	        					done();
	        					value.splice(index,1);
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	        					vue.$message({
	        			        	  showClose: true,
	        			              type: 'success',
	        			              message: '操作成功'
	        			          });
	        				}else{
	        					
	        					done();
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	        					vue.$message({
	        			        	  showClose: true,
	        			              type: 'warning',
	        			              message: data.msg
	        			          });
	    					}
	        			}
	        		});
	              }else{
	                done();
	              }
	          }
		  });
	  },
	//跳转到新页面
	  openTab(url){
		  $.get(url,function(data){
				$('#mainApp').html(data);
		  });
	  },
	  addForm(formName){
		  this.$refs[formName].validate((valid) => {
              if (valid) {
                $.ajax({
    				url : vue.saveUrl,
    				dataType : 'json',
    				type : 'post',
    				async: true,
    				contentType : 'application/json',
    				data :JSON.stringify(vue.mesPermission),
    				success : function(data){
    					if(data.ok){
    						vue.dialogAdd = false;
    			      	  	//刷新页面数据
    			      	  	openTab(vue.toListUrl);
	    			      	  vue.$message({
	    			  	        showClose: true,
	    			  	        message: '操作成功',
	    			  	        type: 'success'
	    			  	      });
    					}else{
    						vue.$message({
	    			  	        showClose: true,
	    			  	        message: data.msg,
	    			  	        type: 'error'
	    			  	      });
    					}
    				}
                });
              } else {
                return false;
              }
          });
	  }
   }
});
	

//载入数据
vue.loadData(vue.currentPage, vue.pagesize);

